<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: #000;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');

    // 图片数量
    const len = 8;
    // 宽高
    const size = 256;
    // 当前帧
    let fm = 0;

    // 建立图像源
    const img = new Image();
    img.src = './images/bomb.jpg';
    img.onload = draw;

    function draw() {
      ctx.drawImage(img, size * fm, 0, size, size, 0, 0, size, size);
      setTimeout(function() {
        fm++;
        if (fm === len) {
          fm = 0;
        }
        draw();
      },100)
    }
  </script>
</body>
</html>